/**
 * Created by Administrator on 2017/7/2.
 */
(function ($) {
    $.widget('learning.tooltip', {
        _create: function () {
            if (!this.options.disabled) {
                this._tooltip = $('<div></div>')
                    .addClass('learning-tooltip-text ui-widget ui-state-hightlight ui-corner-all')
                    .hide()
                    .appendTo('body');

                this.element
                    .addClass('learning-tooltip-trigger')
                    .on('mouseenter.learning.tooltip', $.proxy(this._open, this))
                    .on('mouseleave.learning.tooltip', $.proxy(this._close, this));
            }
        },

        _open: function () {
            var elementOffset = this.element.offset();
            this._tooltip.css({
                position: 'absolute',
                left: elementOffset.left + this.options.offsetX,
                top: elementOffset.top + this.element.height() + this.options.offsetY
            }).text(this.options.content.call(this.element[0]));
            this._tooltip.show(this.options.effect);
            this._trigger('.open');
        },

        _close: function () {
            this._tooltip.hide(this.options.effect);
            this._trigger('.close');
        },

        destory: function () {
            this._tooltip.remove();
            this.element
                .removeClass('learning-tooltip-trigger')
                .off('.learning.tooltip');
            $.Widget.prototype.destory.apply(this, arguments);
        },

        options: {
            offsetX: 10,
            offsetY: 10,
            content: function () {
                return $(this).data('tooltip-text');
            },
            effect: 'explode'
        },

        open: function () {
            this._open();
        },

        close: function () {
            this._close();
        }
    });
})(jQuery);

$(document).ready(function () {
    var value = function () {
        var url = $(this).attr('href');
        return $.get(url).done(function (data) {
            return data;
        });
    };

    $('a').tooltip({
        offsetX: -10,
        offsetY: 25,
        content: value,
        effect: 'fold'
    });
});